<template>
  <view class="rate-amsp">
    <!-- 返回按钮和标题 -->
    <view class="header">
      <tn-button 
        backgroundColor="tn-bg-left" 
        style="color: black; position: absolute; left: 5%; top: 10%; width: 35px; height: 35px; font-size: 25px;" 
        :border="false"
        @click="handleReturn"
      >
        <text class="tn-icon-left"></text>
      </tn-button>
      <view class="page-title">给AMSP一个好评吧</view>
    </view>

    <!-- 评价表单 -->
    <view class="form-container">
      <view class="rating-section">
        <text class="rating-label">评价星级:</text>
        <tn-rate v-model="rating" :max="5" :size="40"></tn-rate>
      </view>

      <view class="feedback-section">
        <text class="feedback-label">您的反馈:</text>
        <textarea 
          v-model="feedback" 
          class="feedback-input" 
          placeholder="请分享您的使用体验"
          :auto-height="true"
        ></textarea>
      </view>

      <tn-button 
        backgroundColor="tn-bg-primary" 
        class="submit-btn"
        @click="submitRating"
        :disabled="!canSubmit"
      >
        提交评价
      </tn-button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      rating: 0,
      feedback: '',
    };
  },
  computed: {
    canSubmit() {
      return this.rating > 0 && this.feedback.trim() !== '';
    }
  },
  methods: {
    // 返回上一页
    handleReturn() {
      uni.navigateBack({ delta: 1 });
    },
    // 提交评价
    submitRating() {
      if (!this.canSubmit) {
        uni.showToast({
          title: '请填写完整信息',
          icon: 'none'
        });
        return;
      }
      // 模拟提交评价
      uni.showToast({
        title: '评价提交成功',
        icon: 'success'
      });
      setTimeout(() => {
        uni.navigateBack({ delta: 1 });
      }, 1500);
    }
  }
};
</script>

<style scoped>
.rate-amsp {
  padding: 20px;
  background-color: #f5f5f5; /* 轻微灰色背景 */
  height: 100%;
}

.header {
  position: relative;
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 10%; /* 增加顶部内边距，确保标题不会被返回按钮遮挡 */
}

.page-title {
  font-size: 28px;
  font-weight: bold;
  position: relative; /* 修改为相对定位 */
  left: 0; /* 重置左偏移 */
  transform: none; /* 重置变换效果 */
  margin-top: 20px; /* 增加顶部外边距，确保标题不会被返回按钮遮挡 */
  color: #333;
  letter-spacing: 1px;
  font-family: "宋体", SimSun, sans-serif; /* 修改字体为宋体 */
}

.form-container {
  background-color: #ffffff;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  padding: 20px;
  margin-top: 40px;
}

.rating-section, .feedback-section {
  margin-bottom: 20px;
}

.rating-label, .feedback-label {
  font-size: 18px;
  color: #555;
  margin-bottom: 10px;
  font-family: "宋体", SimSun, sans-serif; /* 修改字体为宋体 */
}

.feedback-input {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border-radius: 8px;
  border: 1px solid #ccc;
  background-color: #fff;
  transition: border-color 0.3s ease;
  font-family: "宋体", SimSun, sans-serif; /* 修改字体为宋体 */
}

.feedback-input:focus {
  border-color: #4d90fe;
  outline: none;
  box-shadow: 0 0 0 2px #4d90fe;
}

.submit-btn {
  font-size: 18px;
  width: 100%;
  height: 45px;
  margin-top: 30px;
  border-radius: 5px;
  background: linear-gradient(135deg, #6d5dfc 0%, #788eff 100%);
  color: #fff;
  transition: background 0.3s ease;
  font-family: "宋体", SimSun, sans-serif; /* 修改字体为宋体 */
}

.submit-btn:active {
  background: linear-gradient(135deg, #5a4ac6 0%, #667de0 100%);
}
</style>